package cn.jtcoding.web.framework.exception;

import cn.jtcoding.common.framework.enums.ApiResultCode;
import cn.jtcoding.common.framework.vo.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    public ApiResult<String> globalException(Exception e) {
        log.error("", e);
        ApiResult<String> failure = ApiResult.failure(ApiResultCode.UNKNOWN_ERROR);
        failure.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
        return failure;
    }
}